package com.net.TCP04;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务器
 * 1.创建服务器  指定端口ServerSocket（int port）
 *
 * @author jiangbang
 * @date 2016/7/22
 */
public class Server {
    public static void main(String[] args) throws IOException {
        //1、创建服务器   指定端口ServerSocket（int port）
        ServerSocket serverSocket = new ServerSocket(8888);
        //2、接受客户端连接  阻塞式
        Socket socket = serverSocket.accept();
        System.out.println("一个客户端连接");
        //3、发送数据
        String msg = "欢迎使用";
        //输出流
       /* BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"utf-8"));
        bw.write(msg);
        bw.newLine();
        bw.flush();
        bw.close();*/
        DataOutputStream dop = new DataOutputStream(socket.getOutputStream());
        dop.writeUTF(msg);
        dop.flush();
        dop.close();
    }

}
